﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TorchView.GameContent.Data;
using System.ComponentModel;

namespace TorchView.GameContent.Skills
{
  public abstract class SkillRemove : IDataSerializable
  {
    private readonly string _BlockName;
    private readonly string _RemoveTypeName;

    protected SkillRemove(string blockName, string removeTypeName)
    {
      _BlockName = blockName;
      _RemoveTypeName = removeTypeName;
    }

    protected abstract List<string> GetRemoveList();

    public void LoadFromDataBlock(DataBlock block)
    {
      if (block == null)
        throw new ArgumentNullException("block");
      if (block.Name != _BlockName)
        throw new ArgumentException("Incorrect block type, only " + _BlockName + " is supported.");
      Data = block;
      AdditionalDesc = block.GetPropertyValue("ADDITIONALDESCRIPTION", string.Empty);

      var list = GetRemoveList();
      list.Clear();
      list.AddRange(block.GetProperties(_RemoveTypeName).Select(p => p.Value as string).Where(s => s != null));
    }

    public DataBlock MakeDataBlock()
    {
      var block = Data == null ? new DataBlock(_BlockName) : Data;
      block.SetPropertyValue("ADDITIONALDESCRIPTION", AdditionalDesc, PropertyType.TRANSLATE);

      block.RemoveAllProperties(p => p.Name == _RemoveTypeName);
      foreach (var affix in GetRemoveList())
        block.Properties.Add(new DataProperty { Name = _RemoveTypeName, Value = affix, Type = PropertyType.STRING });

      return block;
    }

    public DataBlock Data { get; set; }

    // Properties
    [Description("Additional Description for Skill"), Category("EFFECTS"), DisplayName("Additional Desc.")]
    public string AdditionalDesc { get; set; }

    public override string ToString()
    {
      return _BlockName;
    }
  }
}
